<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>WindowsBatch | lilei</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/images/icons/logo.png">
    <link rel="apple-touch-icon" href="/images/icons/logo.png">
    <link rel="manifest" href="/manifest.json">
    <script type="text/javascript" src="/assets/js/load.js"></script>
    <meta name="description" content="个人网站">
    <meta name="twitter:title" content="WindowsBatch">
    <meta name="twitter:description" content="">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:url" content="http://www.lileiblog.xyz/Shell/WindowsBatch.html">
    <meta property="og:type" content="article">
    <meta property="og:title" content="WindowsBatch">
    <meta property="og:description" content="">
    <meta property="og:url" content="http://www.lileiblog.xyz/Shell/WindowsBatch.html">
    <meta property="og:site_name" content="lilei">
    <meta itemprop="name" content="WindowsBatch">
    <meta itemprop="description" content="">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileImage" content="/images/icons/logo.png">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="keywords" content="lilei,vue,vuepress,vuepress-theme,theme,主题,vuepress主题,blog
        ,vuepress-blog,java,python,shell,sql,golang,script,shell script,nginx,windows,去广告,androd,google drive
        ,one drive,idea,eclipse,git,小程序">
    <meta name="referrer" content="never">
    
    <link rel="preload" href="/assets/css/0.styles.8932179b.css" as="style"><link rel="preload" href="/assets/js/app.269009d6.js" as="script"><link rel="preload" href="/assets/js/3.974b9720.js" as="script"><link rel="preload" href="/assets/js/61.bdfbe584.js" as="script"><link rel="prefetch" href="/assets/js/10.5915e99b.js"><link rel="prefetch" href="/assets/js/11.ff732762.js"><link rel="prefetch" href="/assets/js/12.8bb86d91.js"><link rel="prefetch" href="/assets/js/13.18bde5b0.js"><link rel="prefetch" href="/assets/js/14.314fae34.js"><link rel="prefetch" href="/assets/js/15.0a4ff48f.js"><link rel="prefetch" href="/assets/js/16.ffaf1503.js"><link rel="prefetch" href="/assets/js/17.49a31a6e.js"><link rel="prefetch" href="/assets/js/18.7e6443bf.js"><link rel="prefetch" href="/assets/js/19.6880cc9a.js"><link rel="prefetch" href="/assets/js/20.1fb3f255.js"><link rel="prefetch" href="/assets/js/21.0cd39eea.js"><link rel="prefetch" href="/assets/js/22.392d85cb.js"><link rel="prefetch" href="/assets/js/23.f50adb15.js"><link rel="prefetch" href="/assets/js/24.43e324e1.js"><link rel="prefetch" href="/assets/js/25.e3663205.js"><link rel="prefetch" href="/assets/js/26.da141fb8.js"><link rel="prefetch" href="/assets/js/27.6c05235a.js"><link rel="prefetch" href="/assets/js/28.c124245a.js"><link rel="prefetch" href="/assets/js/29.d185870d.js"><link rel="prefetch" href="/assets/js/30.8587d422.js"><link rel="prefetch" href="/assets/js/31.dc382b56.js"><link rel="prefetch" href="/assets/js/32.20ba32e9.js"><link rel="prefetch" href="/assets/js/33.6ecd7de9.js"><link rel="prefetch" href="/assets/js/34.2b91c13a.js"><link rel="prefetch" href="/assets/js/35.66ed0733.js"><link rel="prefetch" href="/assets/js/36.ce7bca84.js"><link rel="prefetch" href="/assets/js/37.d00bb5ac.js"><link rel="prefetch" href="/assets/js/38.c3ecbb6f.js"><link rel="prefetch" href="/assets/js/39.308f4175.js"><link rel="prefetch" href="/assets/js/4.520f6ecc.js"><link rel="prefetch" href="/assets/js/40.f4b98bc2.js"><link rel="prefetch" href="/assets/js/41.95fae64f.js"><link rel="prefetch" href="/assets/js/42.fe4f877b.js"><link rel="prefetch" href="/assets/js/43.ca8f222e.js"><link rel="prefetch" href="/assets/js/44.4d4ee79e.js"><link rel="prefetch" href="/assets/js/45.79178b33.js"><link rel="prefetch" href="/assets/js/46.c3817d0b.js"><link rel="prefetch" href="/assets/js/47.b8252443.js"><link rel="prefetch" href="/assets/js/48.df9d5d3b.js"><link rel="prefetch" href="/assets/js/49.d812fdb2.js"><link rel="prefetch" href="/assets/js/5.f1a24a16.js"><link rel="prefetch" href="/assets/js/50.55cfcaa8.js"><link rel="prefetch" href="/assets/js/51.b8608b02.js"><link rel="prefetch" href="/assets/js/52.52c5e00d.js"><link rel="prefetch" href="/assets/js/53.3a9bd5fb.js"><link rel="prefetch" href="/assets/js/54.a4240c13.js"><link rel="prefetch" href="/assets/js/55.01c4b876.js"><link rel="prefetch" href="/assets/js/56.f29549a3.js"><link rel="prefetch" href="/assets/js/57.01438a04.js"><link rel="prefetch" href="/assets/js/58.29bb4626.js"><link rel="prefetch" href="/assets/js/59.e8b89408.js"><link rel="prefetch" href="/assets/js/6.8c478b39.js"><link rel="prefetch" href="/assets/js/60.bedb5381.js"><link rel="prefetch" href="/assets/js/62.cb825d1a.js"><link rel="prefetch" href="/assets/js/63.a9516572.js"><link rel="prefetch" href="/assets/js/64.aa854ed7.js"><link rel="prefetch" href="/assets/js/65.285f883d.js"><link rel="prefetch" href="/assets/js/66.12849f37.js"><link rel="prefetch" href="/assets/js/67.c18b00e4.js"><link rel="prefetch" href="/assets/js/68.fa59daa9.js"><link rel="prefetch" href="/assets/js/69.e9d5dda4.js"><link rel="prefetch" href="/assets/js/7.cfb0d0ea.js"><link rel="prefetch" href="/assets/js/70.db126cce.js"><link rel="prefetch" href="/assets/js/71.6acb04cd.js"><link rel="prefetch" href="/assets/js/72.7ff0ab11.js"><link rel="prefetch" href="/assets/js/73.9a66da79.js"><link rel="prefetch" href="/assets/js/74.0a38a030.js"><link rel="prefetch" href="/assets/js/75.7b32dbb3.js"><link rel="prefetch" href="/assets/js/8.cb9c08e5.js"><link rel="prefetch" href="/assets/js/9.ad652cfe.js"><link rel="prefetch" href="/assets/js/vendors~flowchart.110a1065.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8932179b.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/images/icons/logo.png" alt="lilei" class="logo"> <span class="site-name can-hide">lilei</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/Form/" class="nav-link">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link router-link-active">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/Form/" class="nav-link">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link router-link-active">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Shell</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/Shell/" aria-current="page" class="sidebar-link">Shell</a></li><li><a href="/Shell/PowerShell.html" class="sidebar-link">PowerShell</a></li><li><a href="/Shell/ShellScript.html" class="sidebar-link">ShellScript</a></li><li><a href="/Shell/ShellWindows.html" class="sidebar-link">ShellWindows</a></li><li><a href="/Shell/Shell命令.html" class="sidebar-link">Shell命令</a></li><li><a href="/Shell/WindowsBatch.html" aria-current="page" class="active sidebar-link">WindowsBatch</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#flag" class="sidebar-link">Flag</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#文件操作" class="sidebar-link">文件操作</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#环境变量" class="sidebar-link">环境变量</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#ip端口dns进程" class="sidebar-link">IP端口DNS进程</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#延时定时事件任务" class="sidebar-link">延时定时事件任务</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#判断字符串" class="sidebar-link">判断字符串</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#进制转换" class="sidebar-link">进制转换</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#管理员权限" class="sidebar-link">管理员权限</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#隐藏窗口运行" class="sidebar-link">隐藏窗口运行</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#刷新桌面" class="sidebar-link">刷新桌面</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#开机启动" class="sidebar-link">开机启动</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#注册表" class="sidebar-link">注册表</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#注册服务" class="sidebar-link">注册服务</a></li><li class="sidebar-sub-header"><a href="/Shell/WindowsBatch.html#下载文件" class="sidebar-link">下载文件</a></li></ul></li><li><a href="/Shell/WindowsJScript.html" class="sidebar-link">WindowsJScript</a></li><li><a href="/Shell/WindowsScript.html" class="sidebar-link">WindowsScript</a></li><li><a href="/Shell/WindowsVBScript.html" class="sidebar-link">WindowsVBScript</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="windowsbatch"><a href="#windowsbatch" class="header-anchor">#</a> WindowsBatch</h1> <p></p><div class="table-of-contents"><ul><li><a href="#flag">Flag</a></li><li><a href="#文件操作">文件操作</a><ul><li><a href="#获取目录名">获取目录名</a></li><li><a href="#获取为指定后缀的文件">获取为指定后缀的文件</a></li><li><a href="#获取不为指定后缀的文件">获取不为指定后缀的文件</a></li><li><a href="#判断是文件还是文件夹">判断是文件还是文件夹</a></li><li><a href="#替换文件中指定内容">替换文件中指定内容</a></li></ul></li><li><a href="#环境变量">环境变量</a><ul><li><a href="#查看环境变量">查看环境变量</a></li><li><a href="#设置环境变量">设置环境变量</a></li></ul></li><li><a href="#ip端口dns进程">IP端口DNS进程</a><ul><li><a href="#dns">DNS</a></li><li><a href="#查看端口占用">查看端口占用</a></li><li><a href="#查看占用的pid">查看占用的pid</a></li><li><a href="#结束进程">结束进程</a></li></ul></li><li><a href="#延时定时事件任务">延时定时事件任务</a><ul><li><a href="#任务计划">任务计划</a></li><li><a href="#事件">事件</a></li></ul></li><li><a href="#判断字符串">判断字符串</a></li><li><a href="#进制转换">进制转换</a></li><li><a href="#管理员权限">管理员权限</a></li><li><a href="#隐藏窗口运行">隐藏窗口运行</a></li><li><a href="#刷新桌面">刷新桌面</a></li><li><a href="#开机启动">开机启动</a><ul><li><a href="#添加注册表">添加注册表</a></li><li><a href="#启动目录">启动目录</a></li></ul></li><li><a href="#注册表">注册表</a><ul><li><a href="#regini">regini</a></li><li><a href="#修改">修改</a></li><li><a href="#窗口设置">窗口设置</a></li><li><a href="#查询">查询</a></li></ul></li><li><a href="#注册服务">注册服务</a><ul><li><a href="#加入服务">加入服务</a></li><li><a href="#删除服务">删除服务</a></li></ul></li><li><a href="#下载文件">下载文件</a></li></ul></div><p></p> <h2 id="flag"><a href="#flag" class="header-anchor">#</a> Flag</h2> <ul><li><a href="https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/windows-commands" target="_blank" rel="noopener noreferrer">Windows 命令-官方文档<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.cnblogs.com/kekec/p/3662125.html" target="_blank" rel="noopener noreferrer">windows常用命令<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.cnblogs.com/kekec/p/3937530.html" target="_blank" rel="noopener noreferrer">windows批处理语法<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://juejin.im/post/5d50c631518825378d5d6121" target="_blank" rel="noopener noreferrer">windows之四十个bat脚本命令<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://segmentfault.com/a/1190000018614430" target="_blank" rel="noopener noreferrer">windows bat脚本总结<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.thewindowsclub.com/rundll32-shortcut-commands-windows" target="_blank" rel="noopener noreferrer">Windows 10/8/7的Rundll32命令列表<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://gitlab.com/jarv/cmdchallenge" target="_blank" rel="noopener noreferrer">https://gitlab.com/jarv/cmdchallenge<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <ul><li><a href="https://cmdchallenge.com" target="_blank" rel="noopener noreferrer">https://cmdchallenge.com<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul> <ul><li><a href="/files/%E6%B7%BB%E5%8A%A0%E5%BF%AB%E6%8D%B7%E6%96%B9%E5%BC%8F.bat">添加快捷方式</a></li> <li><a href="/files/%E8%AE%BE%E7%BD%AE%E5%BF%85%E5%BA%94%E5%A3%81%E7%BA%B8.bat">设置必应壁纸</a></li> <li><a href="/files/%E8%AE%BE%E7%BD%AEgithub%E7%9A%84hosts.bat">设置GitHub的Hosts</a></li> <li><a href="/files/frpc.bat">frpc.bat</a> 会自动检测本地<code>fprc</code>是否为最新版本，如果不是或者没有则下载最新版</li></ul> <ul><li><code>if</code>和<code>for</code>的条件与后面跟的<code>(</code>之间必须要有一个空格，否则会出现<code>命令语法不正确</code>的问题！</li> <li>使用cd切换目录时，如果带盘符一定要加<code>/d</code>参数，否则切换无效</li> <li>双引号中包含双引号最里层的要用三个<code>&quot;&quot;&quot;</code>转义，<code>&amp;</code>符号要用<code>^</code>转义
<ul><li>示例:使用<code>curl</code>配合<code>jq</code>获取必应壁纸下载地址</li></ul></li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">curl</span> <span class="token string">&quot;http://cn.bing.com/HPImageArchive.aspx?format=js&amp;idx=0&amp;n=1&quot;</span> <span class="token operator">^</span>
 | jq-win64.exe <span class="token string">&quot;.images[0].url | &quot;&quot;&quot;</span>https://cn.bing.com<span class="token string">&quot;&quot;&quot; + .[0:index(&quot;&quot;&quot;</span><span class="token operator">^</span>&amp;<span class="token string">&quot;&quot;&quot;)]&quot;</span> &gt;&gt; bing.txt</span>
</code></pre></div><div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 解压MSI</span>
<span class="token command"><span class="token keyword">msiexec</span> <span class="token parameter attr-name">/a</span> <span class="token string">&quot;MSI文件路径&quot;</span> <span class="token parameter attr-name">/qn</span> TARGETDIR=<span class="token string">&quot;解压输出目录绝对路径&quot;</span></span>
<span class="token comment">:: 弹窗</span>
<span class="token command"><span class="token keyword">msg</span> <span class="token variable">%username%</span> <span class="token parameter attr-name">/time<span class="token punctuation">:</span></span><span class="token number">60</span> <span class="token string">&quot;WARNING:a backdoor account is created&quot;</span></span>
</code></pre></div><ul><li>Windows10当前桌面壁纸：<code>%AppData%\Microsoft\Windows\Themes\CachedFiles\CachedImage_1920_1080_POS4.jpg</code></li> <li>Windows7当前桌面壁纸：<code>%AppData%\Microsoft\Windows\Themes\TranscodedWallpaper.jpg</code></li> <li>事件日志目录：<code>%SystemRoot%\System32\Winevt\Logs</code></li></ul> <h2 id="文件操作"><a href="#文件操作" class="header-anchor">#</a> 文件操作</h2> <ul><li><a href="https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/robocopy" target="_blank" rel="noopener noreferrer">robocopy复制文件及目录结构<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 路径都为文件所在顶级文件夹</span>
<span class="token command"><span class="token keyword">robocopy</span> <span class="token parameter attr-name">/ndl</span> <span class="token parameter attr-name">/njh</span> <span class="token parameter attr-name">/njs</span> <span class="token parameter attr-name">/s</span> 源路径 目的路径 复制的文件多个以空格分隔</span>
</code></pre></div><ul><li><a href="https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/xcopy" target="_blank" rel="noopener noreferrer">xcopy复制文件及目录结构<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/forfiles" target="_blank" rel="noopener noreferrer">forfiles遍历文件夹<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 列出文件，类似于linux下的ls</span>
<span class="token command"><span class="token keyword">dir</span></span>
<span class="token comment">:: 创建目录</span>
<span class="token command"><span class="token keyword">md</span> 目录名（文件夹）</span>
<span class="token comment">:: 删除目录</span>
<span class="token command"><span class="token keyword">rd</span>  目录名（文件夹）</span>
<span class="token comment">:: 拷贝文件</span>
<span class="token command"><span class="token keyword">copy</span> 路径\文件名 路径\文件名</span>
<span class="token comment">:: 移动文件</span>
<span class="token command"><span class="token keyword">move</span> 路径\文件名 路径\文件名</span>
<span class="token comment">:: 删除文件，不能删除文件夹</span>
<span class="token command"><span class="token keyword">del</span> 文件名</span>
</code></pre></div><h3 id="获取目录名"><a href="#获取目录名" class="header-anchor">#</a> 获取目录名</h3> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 顺序循环，设置最后一个为当前目录</span>
<span class="token command"><span class="token keyword">for</span> <span class="token parameter attr-name">/f</span> <span class="token string">&quot;delims=&quot;</span> <span class="token variable">%%i</span> <span class="token keyword">in</span> <span class="token punctuation">(</span><span class="token string">&quot;%cd%&quot;</span><span class="token punctuation">)</span> <span class="token keyword">do</span></span> <span class="token command"><span class="token keyword">set</span> <span class="token variable">folder</span><span class="token operator">=</span><span class="token variable">%%~ni</span></span>
<span class="token command"><span class="token keyword">echo</span> <span class="token variable">%folder%</span></span>

<span class="token comment">:: 仅将 %0 扩充到一个路径</span>
<span class="token command"><span class="token keyword">set</span> <span class="token variable">currentPath</span><span class="token operator">=</span><span class="token variable">%~dp0</span></span>
<span class="token comment">:: 替换\为,号，也可以替换为空格</span>
<span class="token command"><span class="token keyword">set</span> <span class="token variable">currentPath</span><span class="token operator">=</span><span class="token variable">%currentPath:</span>\<span class="token operator">=</span><span class="token punctuation">,</span><span class="token operator">%</span></span>
<span class="token comment">:: 顺序循环，设置最后一个为当前目录</span>
<span class="token command"><span class="token keyword">for</span> <span class="token variable">%%a</span> <span class="token keyword">in</span> <span class="token punctuation">(</span><span class="token variable">%currentPath%</span><span class="token punctuation">)</span> <span class="token keyword">do</span></span> <span class="token command"><span class="token keyword">set</span> <span class="token variable">folder</span><span class="token operator">=</span><span class="token variable">%%a</span></span>
<span class="token command"><span class="token keyword">echo</span> <span class="token variable">%folder%</span></span>
</code></pre></div><h3 id="获取为指定后缀的文件"><a href="#获取为指定后缀的文件" class="header-anchor">#</a> 获取为指定后缀的文件</h3> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">::获取为指定后缀的文件</span>
<span class="token command"><span class="token keyword">for</span> <span class="token parameter attr-name">/r</span> <span class="token variable">%~dp0</span> <span class="token variable">%%a</span> <span class="token keyword">in</span> <span class="token punctuation">(</span>*.jpg<span class="token punctuation">,</span>*.png<span class="token punctuation">)</span> <span class="token keyword">do</span></span> <span class="token punctuation">(</span>
	::把文件后缀赋值给变量
	<span class="token command"><span class="token keyword">set</span> suffix <span class="token operator">=</span> <span class="token variable">%%~xa</span></span>
	::把文件名赋值给变量（没有后缀）
	<span class="token command"><span class="token keyword">set</span> name <span class="token operator">=</span> <span class="token variable">%%~na</span></span>
	::把路径赋值给变量（不带驱动号和文件名）
	<span class="token command"><span class="token keyword">set</span> path <span class="token operator">=</span> <span class="token variable">%%~pa</span></span>
	::把驱动号赋值给变量
	<span class="token command"><span class="token keyword">set</span> drive <span class="token operator">=</span> <span class="token variable">%%~da</span></span>
	
	::判断后缀
	<span class="token command"><span class="token keyword">if</span> <span class="token parameter attr-name">/i</span> <span class="token string">&quot;!suffix!&quot;</span> <span class="token operator">neq</span> <span class="token string">&quot;.bmp&quot;</span></span> <span class="token punctuation">(</span>
		<span class="token command"><span class="token keyword">ren</span> <span class="token string">&quot;%%~a&quot;</span> <span class="token string">&quot;%%~na.bmp&quot;</span></span>
	<span class="token punctuation">)</span>
<span class="token punctuation">)</span>
</code></pre></div><div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">::获取为指定后缀的文件</span>
<span class="token command"><span class="token keyword">for</span> <span class="token parameter attr-name">/f</span> <span class="token string">&quot;delims=&quot;</span> <span class="token variable">%%i</span> <span class="token keyword">in</span> <span class="token punctuation">(</span><span class="token punctuation">'</span>dir <span class="token parameter attr-name">/s</span> <span class="token parameter attr-name">/b</span> <span class="token parameter attr-name">/a</span>  <span class="token variable">%~dp0</span> ^| findstr <span class="token parameter attr-name">/e</span> <span class="token string">&quot;\.jpg\&gt; \.png\&gt;&quot;</span><span class="token punctuation">'</span><span class="token punctuation">)</span> <span class="token keyword">do</span></span> <span class="token punctuation">(</span>
	::把文件后缀写入文件
	<span class="token command"><span class="token keyword">echo</span> <span class="token variable">%%~dpnxi</span> &gt;&gt; test.txt</span>
<span class="token punctuation">)</span>
</code></pre></div><h3 id="获取不为指定后缀的文件"><a href="#获取不为指定后缀的文件" class="header-anchor">#</a> 获取不为指定后缀的文件</h3> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">::获取不为指定后缀的文件</span>
<span class="token command"><span class="token keyword">for</span> <span class="token parameter attr-name">/f</span> <span class="token string">&quot;delims=&quot;</span> <span class="token variable">%%i</span> <span class="token keyword">in</span> <span class="token punctuation">(</span><span class="token punctuation">'</span>dir <span class="token parameter attr-name">/s</span> <span class="token parameter attr-name">/b</span> <span class="token parameter attr-name">/a</span>  <span class="token variable">%~dp0</span> ^| findstr <span class="token parameter attr-name">/v</span> <span class="token string">&quot;\.bat\&gt; \.text\&gt; \.exe\&gt;&quot;</span><span class="token punctuation">'</span><span class="token punctuation">)</span> <span class="token keyword">do</span></span> <span class="token punctuation">(</span>
	::把文件后缀写入文件
	<span class="token command"><span class="token keyword">echo</span> <span class="token variable">%%~dpnxi</span> &gt;&gt; test.txt</span>
<span class="token punctuation">)</span>
</code></pre></div><h3 id="判断是文件还是文件夹"><a href="#判断是文件还是文件夹" class="header-anchor">#</a> 判断是文件还是文件夹</h3> <blockquote><p>如果是文件夹，则<code>test</code>和<code>test\</code>、<code>test\.</code>、<code>test\nul</code>是等同的；
如果是文件，则<code>test</code>不等同于三者中的任何一个</p></blockquote> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">if</span> <span class="token keyword">exist</span> test\</span> <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">echo</span> test 是文件夹</span>
<span class="token punctuation">)</span> <span class="token command"><span class="token keyword">else</span></span> <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">echo</span> test 是文件</span>
<span class="token punctuation">)</span>
</code></pre></div><div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">dir</span> <span class="token parameter attr-name">/ad</span> test &gt;nul <span class="token number">2</span>&gt;nul </span><span class="token operator">&amp;</span><span class="token operator">&amp;</span> <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">echo</span> test 是文件夹</span>
<span class="token punctuation">)</span> || <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">echo</span> test 是文件</span>
<span class="token punctuation">)</span>
</code></pre></div><h3 id="替换文件中指定内容"><a href="#替换文件中指定内容" class="header-anchor">#</a> 替换文件中指定内容</h3> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token operator">@</span><span class="token command"><span class="token keyword">echo</span> off</span>
<span class="token comment">:: 解决把中文写入文件乱码问题（声明采用UTF-8编码），936为GBK，437为美国英语</span>
<span class="token comment">:: https://blog.csdn.net/python_class/article/details/81560470</span>
<span class="token command"><span class="token keyword">chcp</span> <span class="token number">65001</span></span>

<span class="token comment">:: 开启延迟环境变量扩展</span>
<span class="token comment">:: 解决for或if中操作变量时提示ECHO OFF问题，用!!取变量</span>
<span class="token comment">:: 解决调用jscript提示命令错误问题</span>
<span class="token command"><span class="token keyword">setlocal</span> EnableDelayedExpansion</span>

<span class="token command"><span class="token keyword">set</span> <span class="token variable">file</span><span class="token operator">=</span><span class="token variable">%~dp0nav</span>.md</span>
<span class="token comment">:: 替换文件中指定内容</span>
<span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">for</span> <span class="token parameter attr-name">/f</span> <span class="token string">&quot;tokens=*&quot;</span> <span class="token variable">%%i</span> <span class="token keyword">in</span> <span class="token punctuation">(</span><span class="token variable">%file%</span><span class="token punctuation">)</span> <span class="token keyword">do</span></span> <span class="token punctuation">(</span>
        :: 把当前行的内容赋值到变量
        <span class="token command"><span class="token keyword">set</span> <span class="token variable">s</span><span class="token operator">=</span><span class="token variable">%%i</span></span>
        :: 不为空行时
        <span class="token command"><span class="token keyword">if</span> <span class="token keyword">not</span> <span class="token variable">!s!</span>.<span class="token operator">==</span>.</span> <span class="token punctuation">(</span>
            :: 替换内容中的反斜杠为正斜杠
            <span class="token command"><span class="token keyword">set</span> <span class="token variable">s</span><span class="token operator">=</span><span class="token variable">!s:\=/!</span></span>
            <span class="token command"><span class="token keyword">echo</span> <span class="token variable">!s!</span></span>
        <span class="token punctuation">)</span>
    <span class="token punctuation">)</span>
<span class="token punctuation">)</span>&gt;%file%

<span class="token command"><span class="token keyword">goto</span> <span class="token label property">:EXIT</span></span>

<span class="token label property">:EXIT</span>
<span class="token comment">:: 结束延迟环境变量扩展和命令执行</span>
<span class="token command"><span class="token keyword">endlocal</span></span><span class="token operator">&amp;</span><span class="token command"><span class="token keyword">exit</span> <span class="token parameter attr-name">/b</span> <span class="token variable">%errorlevel%</span></span>
</code></pre></div><h2 id="环境变量"><a href="#环境变量" class="header-anchor">#</a> 环境变量</h2> <ul><li><a href="https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/set_1" target="_blank" rel="noopener noreferrer">set<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/setx" target="_blank" rel="noopener noreferrer">setx<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <p><strong><code>SET</code>与<code>SETX</code>的区别</strong></p> <ul><li><code>SET</code> 用于设置临时环境变量和查看环境变量</li> <li><code>SETX</code> 用于设置用户环境变量和系统环境变量</li></ul> <blockquote><p>变量值有空格或<code>%</code>等特殊字符时必须用<code>&quot;</code>包括起来</p></blockquote> <blockquote><p><code>SETX 变量名 变量值</code> 设置用户环境变量，记录在注册表<code>HKEY_CURRENT_USER</code></p></blockquote> <blockquote><p><code>SETX /M 变量名 变量值</code> 设置系统环境变量，记录在注册表<code>HKEY_LOCAL_MACHINE</code></p></blockquote> <h3 id="查看环境变量"><a href="#查看环境变量" class="header-anchor">#</a> 查看环境变量</h3> <ul><li>查看所有环境变量</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 在末尾输入变量名就是查询单个变量</span>
<span class="token command"><span class="token keyword">SET</span></span>
<span class="token comment">:: 或者这样查询单个环境变量</span>
<span class="token command"><span class="token keyword">ECHO</span> <span class="token variable">%PATH%</span></span>
</code></pre></div><ul><li>查看用户环境变量</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 替换最后的*号为变量名就是查询单个变量</span>
<span class="token command"><span class="token keyword">REG</span> QUERY <span class="token string">&quot;HKCU\Environment&quot;</span> <span class="token parameter attr-name">/v</span> *</span>
</code></pre></div><ul><li>查看系统环境变量</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 替换最后的*号为变量名就是查询单个变量</span>
<span class="token command"><span class="token keyword">REG</span> QUERY <span class="token string">&quot;HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment&quot;</span> <span class="token parameter attr-name">/v</span> *</span>
</code></pre></div><h3 id="设置环境变量"><a href="#设置环境变量" class="header-anchor">#</a> 设置环境变量</h3> <ul><li>临时有效</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">set</span> <span class="token variable">path</span><span class="token operator">=</span><span class="token variable">%path%</span>;D:\test</span>
</code></pre></div><ul><li>永久有效</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">setx</span> path <span class="token string">&quot;%path%;D:\test&quot;</span></span>
<span class="token command"><span class="token keyword">setx</span> <span class="token parameter attr-name">/m</span> path <span class="token string">&quot;%path%;D:\test&quot;</span></span>
</code></pre></div><h2 id="ip端口dns进程"><a href="#ip端口dns进程" class="header-anchor">#</a> IP端口DNS进程</h2> <p><strong>查看本机ip</strong></p> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">ipconfig</span></span>
</code></pre></div><h3 id="dns"><a href="#dns" class="header-anchor">#</a> DNS</h3> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">nslookup</span> 域名</span>
</code></pre></div><p><strong>刷新DNS</strong></p> <blockquote><p><code>C:\Windows\System32\drivers\etc\hosts</code></p></blockquote> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">ipconfig</span> <span class="token parameter attr-name">/flushdns</span></span>
</code></pre></div><h3 id="查看端口占用"><a href="#查看端口占用" class="header-anchor">#</a> 查看端口占用</h3> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">netstat</span> -an | find <span class="token string">&quot;0.0.0.0:80&quot;</span></span>
</code></pre></div><h3 id="查看占用的pid"><a href="#查看占用的pid" class="header-anchor">#</a> 查看占用的pid</h3> <blockquote><p>在<code>windows</code>系统下，不能直接使用反引号执行命令，要使用<code>for</code>循环变通下，在<code>for</code>循环中使用单<code>'</code>括起来执行命令</p></blockquote> <blockquote><p>在<code>cmd</code>命令窗口中直接使用<code>for</code>循环只能使用单<code>%</code>设置变量</p> <p>而在<code>bat</code>脚本文件中只能用双<code>%%</code>设置变量</p> <p>而且在<code>for</code>循环中执行的命令带有<code>|</code>等特殊符号需要使用<code>^</code>转义</p></blockquote> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 用findstr命令搜索</span>
<span class="token command"><span class="token keyword">for</span> <span class="token parameter attr-name">/f</span> <span class="token variable">%%i</span> <span class="token keyword">in</span> <span class="token punctuation">(</span><span class="token punctuation">'</span>tasklist ^| findstr <span class="token parameter attr-name">/i</span> <span class="token string">&quot;程序名&quot;</span><span class="token punctuation">'</span><span class="token punctuation">)</span> <span class="token keyword">do</span></span> <span class="token command"><span class="token keyword">set</span> <span class="token variable">reslut</span><span class="token operator">=</span><span class="token variable">%%i</span></span>

<span class="token comment">:: 只输出PID编号</span>
<span class="token command"><span class="token keyword">for</span> <span class="token parameter attr-name">/f</span> <span class="token string">&quot;skip=3 tokens=2&quot;</span> <span class="token variable">%a</span> <span class="token keyword">in</span> <span class="token punctuation">(</span><span class="token punctuation">'</span>tasklist <span class="token parameter attr-name">/fi</span> <span class="token string">&quot;imagename eq 程序名*&quot;</span><span class="token punctuation">'</span><span class="token punctuation">)</span> <span class="token keyword">do</span></span> <span class="token operator">@</span><span class="token command"><span class="token keyword">echo</span> <span class="token variable">%a</span></span>
</code></pre></div><p><strong>查看被占用端口的<code>pid</code></strong></p> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">netstat</span> -ano | findstr <span class="token number">80</span></span>
</code></pre></div><h3 id="结束进程"><a href="#结束进程" class="header-anchor">#</a> 结束进程</h3> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">taskkill</span> <span class="token parameter attr-name">/pid</span> 进程号 <span class="token parameter attr-name">/f</span></span>
<span class="token command"><span class="token keyword">taskkill</span> <span class="token parameter attr-name">/f</span> <span class="token parameter attr-name">/im</span> 程序名</span>
</code></pre></div><h2 id="延时定时事件任务"><a href="#延时定时事件任务" class="header-anchor">#</a> 延时定时事件任务</h2> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 延时等待10秒</span>
<span class="token command"><span class="token keyword">choice</span> <span class="token parameter attr-name">/t</span> <span class="token number">10</span> <span class="token parameter attr-name">/d</span> y <span class="token parameter attr-name">/n</span> &gt;nul</span>
<span class="token comment">:: 延时等待10秒</span>
<span class="token command"><span class="token keyword">timeout</span> <span class="token parameter attr-name">/T</span> <span class="token number">10</span> <span class="token parameter attr-name">/NOBREAK</span></span>
<span class="token comment">:: 持续等待，直到按下任意按键，类似于pause</span>
<span class="token command"><span class="token keyword">timeout</span> <span class="token parameter attr-name">/T</span> <span class="token number">-1</span></span>
<span class="token comment">:: 持续等待，直到你按下CTRL+C按键</span>
<span class="token command"><span class="token keyword">timeout</span> <span class="token parameter attr-name">/T</span> <span class="token number">-1</span> <span class="token parameter attr-name">/NOBREAK</span></span>
</code></pre></div><h3 id="任务计划"><a href="#任务计划" class="header-anchor">#</a> 任务计划</h3> <ul><li><a href="https://www.cnblogs.com/daimaxuejia/p/12957644.html" target="_blank" rel="noopener noreferrer">Schtasks命令详解<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.microsoft.com/zh-cn/windows/win32/taskschd/task-scheduler-reference" target="_blank" rel="noopener noreferrer">任务计划程序参考<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><a href="https://github.com/dahall/TaskScheduler" target="_blank" rel="noopener noreferrer">https://github.com/dahall/TaskScheduler<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/fireeye/SharPersist" target="_blank" rel="noopener noreferrer">https://github.com/fireeye/SharPersist<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <p><strong>更高级用法见<a href="/Shell/WindowsJScript.html#创建任务计划">创建任务计划</a></strong></p> <blockquote><p>如果任务计划运行没反应，去掉<code>/RU SYSTEM</code>试试</p></blockquote> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">taskschd</span></span>
<span class="token command"><span class="token keyword">SCHTASKS</span> <span class="token parameter attr-name">/?</span> 查看帮助</span>

<span class="token comment">:: /sc 指定计划频率：MINUTE、 HOURLY、DAILY、WEEKLY、MONTHLY, ONCE, ONSTART, ONLOGON, ONIDLE, ONEVENT</span>
<span class="token command"><span class="token keyword">SCHTASKS</span> <span class="token parameter attr-name">/Create</span> <span class="token parameter attr-name">/RU</span> SYSTEM <span class="token parameter attr-name">/RL</span> Highest <span class="token parameter attr-name">/tn</span> 定时任务名 <span class="token parameter attr-name">/tr</span> <span class="token string">&quot;运行程序路径&quot;</span> <span class="token parameter attr-name">/sc</span> DAILY</span>
<span class="token comment">:: 开机自启动</span>
<span class="token command"><span class="token keyword">SCHTASKS</span> <span class="token parameter attr-name">/Create</span> <span class="token parameter attr-name">/RU</span> SYSTEM <span class="token parameter attr-name">/RL</span> Highest <span class="token parameter attr-name">/tn</span> 定时任务名 <span class="token parameter attr-name">/tr</span> <span class="token string">&quot;运行程序路径&quot;</span> <span class="token parameter attr-name">/sc</span> ONSTART</span>
<span class="token comment">:: 每天 12:30 运行</span>
<span class="token command"><span class="token keyword">schtasks</span> <span class="token parameter attr-name">/Create</span> <span class="token parameter attr-name">/RU</span> SYSTEM <span class="token parameter attr-name">/RL</span> Highest <span class="token parameter attr-name">/tn</span> 定时任务名 <span class="token parameter attr-name">/tr</span> <span class="token string">&quot;运行程序路径&quot;</span> <span class="token parameter attr-name">/sc</span> DAILY <span class="token parameter attr-name">/st</span> <span class="token number">12</span>:<span class="token number">30</span></span>
<span class="token comment">:: 一分钟执行一次</span>
<span class="token command"><span class="token keyword">schtasks</span> <span class="token parameter attr-name">/Create</span> <span class="token parameter attr-name">/RU</span> SYSTEM <span class="token parameter attr-name">/RL</span> Highest <span class="token parameter attr-name">/tn</span> 定时任务名 <span class="token parameter attr-name">/tr</span> <span class="token string">&quot;运行程序路径&quot;</span> <span class="token parameter attr-name">/sc</span> MINUTE <span class="token parameter attr-name">/mo</span> <span class="token number">1</span></span>
<span class="token comment">:: 在指定的开始日期和结束日期之间，每天 12:00 点开始到 14:00 点，每隔5分钟运行</span>
<span class="token command"><span class="token keyword">SCHTASKS</span> <span class="token parameter attr-name">/Create</span> <span class="token parameter attr-name">/RU</span> SYSTEM <span class="token parameter attr-name">/RL</span> Highest <span class="token parameter attr-name">/tn</span> 定时任务名 <span class="token parameter attr-name">/TR</span> <span class="token string">&quot;运行程序路径&quot;</span> <span class="token parameter attr-name">/SD</span> 开始日期 <span class="token parameter attr-name">/ED</span> 结束日期 <span class="token operator">^</span>
 <span class="token parameter attr-name">/ST</span> <span class="token number">12</span>:<span class="token number">00</span> <span class="token parameter attr-name">/ET</span> <span class="token number">14</span>:<span class="token number">00</span> <span class="token parameter attr-name">/SC</span> MINUTE <span class="token parameter attr-name">/MO</span> <span class="token number">5</span></span>
<span class="token comment">:: 每天 12:00 点开始到 14:00 点自动结束</span>
<span class="token command"><span class="token keyword">SCHTASKS</span> <span class="token parameter attr-name">/Create</span> <span class="token parameter attr-name">/RU</span> SYSTEM <span class="token parameter attr-name">/RL</span> Highest <span class="token parameter attr-name">/tn</span> 定时任务名 <span class="token parameter attr-name">/TR</span> <span class="token string">&quot;运行程序路径&quot;</span> <span class="token parameter attr-name">/ST</span> <span class="token number">12</span>:<span class="token number">00</span> <span class="token parameter attr-name">/ET</span> <span class="token number">14</span>:<span class="token number">00</span> <span class="token parameter attr-name">/K</span> <span class="token parameter attr-name">/SC</span> DAILY</span>
<span class="token comment">:: 将任务附加到事件上：登录成功事件，运行事件查看器</span>
<span class="token command"><span class="token keyword">SCHTASKS</span> <span class="token parameter attr-name">/Create</span> <span class="token parameter attr-name">/RU</span> SYSTEM <span class="token parameter attr-name">/RL</span> Highest <span class="token parameter attr-name">/tn</span> 定时任务名 <span class="token parameter attr-name">/TR</span> eventvwr <span class="token parameter attr-name">/SC</span> ONEVENT <span class="token parameter attr-name">/EC</span> Security <span class="token operator">^</span>
 <span class="token parameter attr-name">/MO</span> <span class="token string">&quot;*[System[Provider[@Name='Microsoft-Windows-Security-Auditing'] and EventID=4624]]&quot;</span></span>
<span class="token comment">:: 将任务附加到事件上：系统已从低功耗状态中恢复，运行事件查看器</span>
<span class="token command"><span class="token keyword">SCHTASKS</span> <span class="token parameter attr-name">/Create</span> <span class="token parameter attr-name">/RU</span> SYSTEM <span class="token parameter attr-name">/RL</span> Highest <span class="token parameter attr-name">/tn</span> 定时任务名 <span class="token parameter attr-name">/TR</span> eventvwr <span class="token parameter attr-name">/SC</span> ONEVENT <span class="token parameter attr-name">/EC</span> System <span class="token operator">^</span>
 <span class="token parameter attr-name">/MO</span> <span class="token string">&quot;*[System[Provider[@Name='Microsoft-Windows-Power-Troubleshooter'] and EventID=1]]&quot;</span></span>

<span class="token comment">:: 查询任务</span>
<span class="token command"><span class="token keyword">SCHTASKS</span> <span class="token parameter attr-name">/Query</span> <span class="token parameter attr-name">/fo</span> LIST <span class="token parameter attr-name">/v</span> <span class="token parameter attr-name">/TN</span> 任务名称</span>
<span class="token comment">:: 强制删除任务</span>
<span class="token command"><span class="token keyword">SCHTASKS</span> <span class="token parameter attr-name">/Delete</span> <span class="token parameter attr-name">/F</span> <span class="token parameter attr-name">/TN</span> 任务名称</span>
<span class="token comment">:: 手动运行任务</span>
<span class="token command"><span class="token keyword">SCHTASKS</span> <span class="token parameter attr-name">/run</span> <span class="token parameter attr-name">/TN</span> 任务名称</span>
</code></pre></div><h3 id="事件"><a href="#事件" class="header-anchor">#</a> 事件</h3> <ul><li><a href="https://docs.microsoft.com/zh-cn/windows/win32/events/windows-events" target="_blank" rel="noopener noreferrer">https://docs.microsoft.com/zh-cn/windows/win32/events/windows-events<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.microsoft.com/zh-cn/previous-versions//aa385231(v=vs.85)" target="_blank" rel="noopener noreferrer">https://docs.microsoft.com/zh-cn/previous-versions//aa385231(v=vs.85)<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.microsoft.com/zh-cn/windows/win32/wes/windows-event-log" target="_blank" rel="noopener noreferrer">https://docs.microsoft.com/zh-cn/windows/win32/wes/windows-event-log<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><code>eventvwr</code> 打开事件查看器
<ul><li>打开eventvwr -&gt; Windows 日志 -&gt; 系统 右键打开菜单 -&gt; 将所有事件另存为(E) -&gt; 选择保存类型为xml</li></ul></li> <li><code>eventcreate</code> 该命令行工具使管理员能够创建一个自定义事件 ID 和消息于某指定事件日志里。</li> <li><code>wmic ntevent /?</code> <ul><li><code>wmic ntevent list full</code> 查看所有事件日志</li></ul></li> <li><code>wmic nteventlog /?</code></li> <li><code>wevtutil.exe qe Application /c:3 /rd:true /f:text</code></li> <li><code>(get-winevent -listlog Application).providernames</code> 或者 <code>wevtutil el</code> 查看所有事件名</li> <li><code>计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WINEVT\Publishers</code> 注册表中所有事件</li></ul> <table><thead><tr><th>事件源</th> <th>事件ID</th> <th>说明</th></tr></thead> <tbody><tr><td>Power-Troubleshooter</td> <td>1</td> <td>系统已从低功耗状态中恢复。</td></tr> <tr><td>Kernel-Power</td> <td>42</td> <td>系统正在进入睡眠状态。</td></tr> <tr><td>Kernel-Power</td> <td>105</td> <td>电源更改。</td></tr> <tr><td>Kernel-Power</td> <td>107</td> <td>系统已从睡眠状态恢复。（已进入睡眠状态）</td></tr> <tr><td>Kernel-Power</td> <td>130</td> <td>系统开机恢复</td></tr> <tr><td>Kernel-Power</td> <td>131</td> <td>系统开机恢复</td></tr> <tr><td>Kernel-General</td> <td>1</td> <td>更改系统时间</td></tr> <tr><td>Kernel-General</td> <td>24</td> <td>已刷新时区信息，退出原因为 0。当前时区偏差为 -480。</td></tr> <tr><td>EventLog</td> <td>6013</td> <td>系统启动时间为 178611 秒。</td></tr></tbody></table> <h2 id="判断字符串"><a href="#判断字符串" class="header-anchor">#</a> 判断字符串</h2> <blockquote><p>注意：在|两端不能有空格，如果有空格则会出现匹配不正确</p> <p>这里有个BUG不能取反匹配，比如用<code>[^0-9]</code>匹配不是纯数字的字符，匹配到<code>.</code>会通过</p></blockquote> <p><strong>判断是否为数字、字母</strong></p> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 判断是否为数字、字母，在|两端不能有空格</span>
<span class="token comment">:: 注意这里有个bug不能用[^0-9]取反，匹配到.会通过</span>
<span class="token command"><span class="token keyword">echo</span> <span class="token variable">%var%</span>|findstr <span class="token string">&quot;^[a-z0-9]*$&quot;</span> &gt;nul </span><span class="token operator">&amp;</span><span class="token operator">&amp;</span> <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">ECHO</span>.</span>
    <span class="token command"><span class="token keyword">ECHO</span>.输入的：<span class="token variable">%var%</span></span>
    <span class="token command"><span class="token keyword">ECHO</span>.</span>
<span class="token punctuation">)</span> || <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">ECHO</span>.</span>
    <span class="token command"><span class="token keyword">ECHO</span>.输入的必须为纯小写字母或数字！</span>
    <span class="token command"><span class="token keyword">ECHO</span>.</span>
<span class="token punctuation">)</span>
</code></pre></div><p><strong>判断是否为纯数字</strong></p> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 判断是否为纯数字，在|两端不能有空格</span>
<span class="token comment">:: 注意这里有个bug不能用[^0-9]取反，匹配到.会通过</span>
<span class="token command"><span class="token keyword">echo</span> <span class="token variable">%port%</span>|findstr <span class="token string">&quot;^[0-9]*$&quot;</span> &gt;nul </span><span class="token operator">&amp;</span><span class="token operator">&amp;</span> <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">ECHO</span>.</span>
    <span class="token command"><span class="token keyword">ECHO</span>.输入的端口：<span class="token variable">%port%</span></span>
    <span class="token command"><span class="token keyword">ECHO</span>.</span>
<span class="token punctuation">)</span> || <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">ECHO</span>.</span>
    <span class="token command"><span class="token keyword">ECHO</span>.端口必须为纯数字！</span>
    <span class="token command"><span class="token keyword">ECHO</span>.</span>
<span class="token punctuation">)</span>
</code></pre></div><p><strong>判断字符串是否包含子字符串</strong></p> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 判断变量字符串中是否包含字符串</span>
<span class="token command"><span class="token keyword">echo</span> %字符串% | findstr %子串% &gt;nul </span><span class="token operator">&amp;</span><span class="token operator">&amp;</span> <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">echo</span> 包含</span>
<span class="token punctuation">)</span> || <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">echo</span> 不包含</span>
<span class="token punctuation">)</span>
</code></pre></div><div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">set</span> <span class="token variable">error</span><span class="token operator">=</span><span class="token number">1</span></span>
<span class="token comment">:: 判断文件中是否包含字符串</span>
<span class="token command"><span class="token keyword">findstr</span><span class="token parameter attr-name">/i</span> <span class="token string">&quot;123&quot;</span> <span class="token number">1</span>.txt &gt;nul <span class="token number">2</span>&gt;nul</span><span class="token operator">&amp;</span><span class="token operator">&amp;</span><span class="token command"><span class="token keyword">set</span> <span class="token string">&quot;error=&quot;</span></span>
<span class="token command"><span class="token keyword">if</span> <span class="token keyword">defined</span> error</span> <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">echo</span> 不包含</span>
<span class="token punctuation">)</span> <span class="token command"><span class="token keyword">else</span></span> <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">echo</span> 包含</span>
<span class="token punctuation">)</span>
</code></pre></div><h2 id="进制转换"><a href="#进制转换" class="header-anchor">#</a> 进制转换</h2> <ul><li>十进制转十六进制</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token operator">@</span><span class="token command"><span class="token keyword">echo</span> off</span><span class="token operator">&amp;</span><span class="token command"><span class="token keyword">setlocal</span> enabledelayedexpansion</span>
<span class="token command"><span class="token keyword">set</span> <span class="token parameter attr-name">/p</span> 十进制<span class="token operator">=</span>请输入要转换的十进制数：</span>
<span class="token command"><span class="token keyword">for</span> <span class="token parameter attr-name">/l</span> <span class="token variable">%%a</span> <span class="token keyword">in</span> <span class="token punctuation">(</span><span class="token number">1</span> <span class="token number">1</span> <span class="token number">8</span><span class="token punctuation">)</span> <span class="token keyword">do</span></span> <span class="token punctuation">(</span>
     <span class="token command"><span class="token keyword">set</span> <span class="token parameter attr-name">/a</span> 余<span class="token operator">=</span>十进制<span class="token variable">%%16</span><span class="token punctuation">,</span>十进制<span class="token operator">/=</span><span class="token number">16</span><span class="token punctuation">,</span><span class="token variable">tmp</span><span class="token operator">=</span>余<span class="token operator">+</span><span class="token number">100</span></span>
     <span class="token command"><span class="token keyword">set</span> <span class="token variable">yu</span><span class="token operator">=</span><span class="token variable">!tmp:~1!</span> <span class="token variable">!yu!</span></span>
<span class="token punctuation">)</span>
<span class="token command"><span class="token keyword">set</span> <span class="token variable">yu</span><span class="token operator">=</span><span class="token variable">%yu:00</span><span class="token operator">=</span><span class="token number">0</span><span class="token operator">%</span></span>
<span class="token command"><span class="token keyword">for</span> <span class="token variable">%%a</span> <span class="token keyword">in</span> <span class="token punctuation">(</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span> <span class="token number">4</span> <span class="token number">5</span> <span class="token number">6</span> <span class="token number">7</span> <span class="token number">8</span> <span class="token number">9</span> A B C D E F<span class="token punctuation">)</span> <span class="token keyword">do</span></span> <span class="token punctuation">(</span>
     <span class="token command"><span class="token keyword">set</span> <span class="token parameter attr-name">/a</span> <span class="token variable">n</span><span class="token operator">+=</span><span class="token number">101</span></span>
     <span class="token command"><span class="token keyword">for</span> <span class="token variable">%%b</span> <span class="token keyword">in</span> <span class="token punctuation">(</span><span class="token variable">!n:~-2!</span><span class="token punctuation">)</span> <span class="token keyword">do</span></span> <span class="token punctuation">(</span>
         <span class="token command"><span class="token keyword">set</span> <span class="token variable">yu</span><span class="token operator">=</span><span class="token operator">!</span>yu: <span class="token variable">%%b</span><span class="token operator">=</span> <span class="token variable">%%a</span><span class="token operator">!</span></span>
     <span class="token punctuation">)</span>
<span class="token punctuation">)</span>
<span class="token command"><span class="token keyword">echo</span> 0x<span class="token variable">%yu:</span> =%</span>
<span class="token command"><span class="token keyword">pause</span></span>
</code></pre></div><ul><li>十六进制转十进制</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">set</span> <span class="token parameter attr-name">/p</span> 十六进制<span class="token operator">=</span>请输入十六进制数字：</span>
<span class="token command"><span class="token keyword">set</span> <span class="token parameter attr-name">/a</span> 十进制<span class="token operator">=</span>0x<span class="token operator">%</span>十六进制:<span class="token operator">*</span><span class="token variable">x</span><span class="token operator">=</span><span class="token operator">%</span></span>
<span class="token command"><span class="token keyword">echo</span> %十进制%</span>
</code></pre></div><h2 id="管理员权限"><a href="#管理员权限" class="header-anchor">#</a> 管理员权限</h2> <ul><li><p>Windows10启用管理员：快捷键<kbd>Win</kbd> + <kbd>r</kbd> 打开“运行”输入<code>gpedit.msc</code>并运行 -&gt; <code>Windows 设置</code> -&gt; <code>安全设置</code> -&gt; <code>安全选项</code></p> <ul><li>禁用：<code>用户账户控制：以管理员批准模式运行所有管理员</code></li> <li>禁用：<code>用户账户控制：用于内置管理员账户的管理员批准模式</code></li> <li>启用：<code>账户：管理员账户状态</code></li></ul></li> <li><p>判断</p></li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">md</span> <span class="token string">&quot;%~dp0$testAdmin$&quot;</span> <span class="token number">2</span>&gt;nul</span>
<span class="token command"><span class="token keyword">if</span> <span class="token keyword">not</span> <span class="token keyword">exist</span> <span class="token string">&quot;%~dp0$testAdmin$&quot;</span></span> <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">echo</span> 不具备所在目录的写入权限! &gt;</span><span class="token operator">&amp;</span><span class="token command"><span class="token keyword">2</span></span>
    <span class="token command"><span class="token keyword">exit</span> <span class="token parameter attr-name">/b</span> <span class="token number">1</span></span>
<span class="token punctuation">)</span> <span class="token command"><span class="token keyword">else</span></span> <span class="token command"><span class="token keyword">rd</span> <span class="token string">&quot;%~dp0$testAdmin$&quot;</span></span>
</code></pre></div><div class="language-batch extra-class"><pre class="language-batch"><code><span class="token operator">@</span><span class="token command"><span class="token keyword">echo</span> off</span>
<span class="token comment">:: 检查权限</span>
&gt;nul 2&gt;<span class="token operator">&amp;</span><span class="token command"><span class="token keyword">1</span> <span class="token string">&quot;%SYSTEMROOT%\system32\cacls.exe&quot;</span> <span class="token string">&quot;%SYSTEMROOT%\system32\config\system&quot;</span></span>
<span class="token comment">:: 如果没有管理员权限，就请求管理权限</span>
<span class="token command"><span class="token keyword">if</span> '%<span class="token keyword">errorlevel</span>%' <span class="token operator">NEQ</span> '<span class="token number">0</span>'</span> <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">echo</span> 不具备所在目录的写入权限! &gt;</span><span class="token operator">&amp;</span><span class="token command"><span class="token keyword">2</span></span>
    <span class="token command"><span class="token keyword">exit</span> <span class="token parameter attr-name">/b</span> <span class="token number">1</span></span>
<span class="token punctuation">)</span>
</code></pre></div><div class="language-batch extra-class"><pre class="language-batch"><code><span class="token operator">@</span><span class="token command"><span class="token keyword">echo</span> off</span>
<span class="token comment">:: 检查权限</span>
<span class="token command"><span class="token keyword">net</span> session &gt;nul <span class="token number">2</span>&gt;</span><span class="token operator">&amp;</span><span class="token command"><span class="token keyword">1</span> </span>
<span class="token command"><span class="token keyword">if</span> not <span class="token string">&quot;%errorLevel%&quot;</span> == <span class="token string">&quot;0&quot;</span> ( </span>
    <span class="token command"><span class="token keyword">echo</span> 不具备所在目录的写入权限! &gt;</span><span class="token operator">&amp;</span><span class="token command"><span class="token keyword">2</span></span>
    <span class="token command"><span class="token keyword">exit</span> <span class="token parameter attr-name">/b</span> <span class="token number">1</span></span>
<span class="token punctuation">)</span>
</code></pre></div><div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">reg</span> query HKU\S<span class="token number">-1</span><span class="token number">-5</span><span class="token number">-20</span>&gt;nul <span class="token number">2</span>&gt;nul</span>
<span class="token command"><span class="token keyword">if</span> not <span class="token string">&quot;%errorLevel%&quot;</span> == <span class="token string">&quot;0&quot;</span> ( </span>
    <span class="token command"><span class="token keyword">echo</span> 不具备所在目录的写入权限! &gt;</span><span class="token operator">&amp;</span><span class="token command"><span class="token keyword">2</span></span>
    <span class="token command"><span class="token keyword">exit</span> <span class="token parameter attr-name">/b</span> <span class="token number">1</span></span>
<span class="token punctuation">)</span>
</code></pre></div><p><strong>获取管理员权限</strong></p> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token operator">@</span><span class="token command"><span class="token keyword">echo</span> off</span>
<span class="token command"><span class="token keyword">fltmc</span>&gt;nul||cd<span class="token parameter attr-name">/d</span> <span class="token variable">%~dp0</span> </span><span class="token operator">&amp;</span><span class="token operator">&amp;</span> <span class="token command"><span class="token keyword">mshta</span> vbscript:CreateObject(<span class="token string">&quot;Shell.Application&quot;</span></span><span class="token punctuation">)</span>.ShellExecute<span class="token punctuation">(</span>&quot;%~nx0&quot;,&quot;%1&quot;,&quot;&quot;,&quot;runas&quot;,0<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token command"><span class="token keyword">window</span>.close</span><span class="token punctuation">)</span>

<span class="token comment">:: 下面为执行命令</span>

</code></pre></div><div class="language-batch extra-class"><pre class="language-batch"><code><span class="token operator">@</span><span class="token command"><span class="token keyword">echo</span> off</span>
<span class="token comment">::-------------------------------------------------------------------------------</span>
&gt;nul 2&gt;<span class="token operator">&amp;</span><span class="token command"><span class="token keyword">1</span> <span class="token string">&quot;%SYSTEMROOT%\system32\cacls.exe&quot;</span> <span class="token string">&quot;%SYSTEMROOT%\system32\config\system&quot;</span></span>
<span class="token command"><span class="token keyword">if</span> '%<span class="token keyword">errorlevel</span>%' <span class="token operator">NEQ</span> '<span class="token number">0</span>'</span> <span class="token punctuation">(</span> <span class="token command"><span class="token keyword">goto</span> UACPrompt </span><span class="token punctuation">)</span> <span class="token command"><span class="token keyword">else</span></span> <span class="token punctuation">(</span> <span class="token command"><span class="token keyword">goto</span> GetAdmin </span><span class="token punctuation">)</span>
<span class="token label property">:UACPrompt</span>
    ::if not &quot;%~1&quot;==&quot;&quot; set file= &quot;&quot;%~1&quot;&quot;
    ::echo CreateObject<span class="token punctuation">(</span>&quot;Shell.Application&quot;<span class="token punctuation">)</span>.ShellExecute &quot;cmd.exe&quot;, &quot;/c %~s0%file%&quot;, &quot;&quot;, &quot;runas&quot;, 0 &gt; &quot;%temp%\getadmin.vbs&quot;
    <span class="token command"><span class="token keyword">echo</span> CreateObject<span class="token operator">^</span>(<span class="token string">&quot;Shell.Application&quot;</span><span class="token operator">^</span>).ShellExecute <span class="token string">&quot;%~s0&quot;</span>, <span class="token string">&quot;%*&quot;</span>, <span class="token string">&quot;&quot;</span>, <span class="token string">&quot;runas&quot;</span>, <span class="token number">0</span> &gt; <span class="token string">&quot;%temp%\getadmin.vbs&quot;</span> </span>
    &quot;%temp%\getadmin.vbs&quot;
    <span class="token command"><span class="token keyword">exit</span> <span class="token parameter attr-name">/B</span></span>
<span class="token label property">:GetAdmin</span>
    <span class="token command"><span class="token keyword">if</span> <span class="token keyword">exist</span> <span class="token string">&quot;%temp%\getadmin.vbs&quot;</span></span> <span class="token punctuation">(</span> <span class="token command"><span class="token keyword">del</span> <span class="token string">&quot;%temp%\getadmin.vbs&quot;</span> </span><span class="token punctuation">)</span>
    <span class="token command"><span class="token keyword">pushd</span> <span class="token string">&quot;%CD%&quot;</span></span>
    <span class="token command"><span class="token keyword">CD</span> <span class="token parameter attr-name">/D</span> <span class="token string">&quot;%~dp0&quot;</span></span>
<span class="token label property">:StartCommand</span>
<span class="token comment">::-------------------------------------------------------------------------------</span>

<span class="token comment">:: 下面为执行命令</span>

</code></pre></div><h2 id="隐藏窗口运行"><a href="#隐藏窗口运行" class="header-anchor">#</a> 隐藏窗口运行</h2> <p><strong>此方式完全不会显示<code>CMD</code>窗口（包括闪现） <a href="/Shell/WindowsScript.html#vbs函数封装">vbs脚本</a></strong></p> <p><strong>此方式会闪现<code>CMD</code>窗口 bat脚本</strong></p> <blockquote><p>如果运行的批处理名为<code>a.bat</code>，在<code>C:\</code>下，那<code>%~0</code>代表<code>C:\a.bat</code>，<code>%~nx0</code>代表<code>a.bat</code>。<code>h</code>极为参数<code>%1</code>，<code>0</code>表示隐藏运行。</p> <p>由于你双击运行，故第一次批处理<code>%1</code>为空，<code>if</code>不成立，转而运行下一句。
然后再次打开自己，并传递参数<code>h</code>，此时<code>if</code>成立，跳转至<code>begin</code>开始运行。</p></blockquote> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token operator">@</span><span class="token command"><span class="token keyword">echo</span> off</span>
<span class="token command"><span class="token keyword">if</span> <span class="token string">&quot;%1&quot;</span> == <span class="token string">&quot;h&quot;</span> goto begin</span>
<span class="token command"><span class="token keyword">mshta</span> vbscript:createobject(<span class="token string">&quot;wscript.shell&quot;</span></span><span class="token punctuation">)</span>.run<span class="token punctuation">(</span>&quot;%~0 h&quot;,0<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token command"><span class="token keyword">window</span>.close</span><span class="token punctuation">)</span><span class="token operator">&amp;</span><span class="token operator">&amp;</span><span class="token command"><span class="token keyword">exit</span></span>
<span class="token comment">::mshta &quot;javascript:new ActiveXObject('WScript.Shell').Run('%~0 h',0);window.close()&quot;&amp;&amp;exit</span>
<span class="token label property">:begin</span>

<span class="token comment">:: 下面为执行命令</span>

</code></pre></div><div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 静默运行软件</span>
<span class="token command"><span class="token keyword">Pushd</span> <span class="token variable">%~dp0</span></span>
<span class="token command"><span class="token keyword">start</span> <span class="token parameter attr-name">/wait</span> <span class="token parameter attr-name">/B</span> <span class="token string">&quot;&quot;</span> <span class="token string">&quot;%~dp0软件名称&quot;</span> <span class="token parameter attr-name">/S</span></span>
</code></pre></div><div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 添加开机静默启动</span>
<span class="token command"><span class="token keyword">Pushd</span> <span class="token variable">%~dp0</span></span>
<span class="token command"><span class="token keyword">start</span> <span class="token parameter attr-name">/wait</span> <span class="token parameter attr-name">/B</span> <span class="token string">&quot;&quot;</span> <span class="token string">&quot;%~dp0软件名称&quot;</span> <span class="token parameter attr-name">/ADD</span></span>
</code></pre></div><div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 删除开机静默启动</span>
<span class="token command"><span class="token keyword">Pushd</span> <span class="token variable">%~dp0</span></span>
<span class="token command"><span class="token keyword">start</span> <span class="token parameter attr-name">/wait</span> <span class="token parameter attr-name">/B</span> <span class="token string">&quot;&quot;</span> <span class="token string">&quot;%~dp0软件名称&quot;</span> <span class="token parameter attr-name">/DEL</span></span>
</code></pre></div><h2 id="刷新桌面"><a href="#刷新桌面" class="header-anchor">#</a> 刷新桌面</h2> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">REM taskkill 用户窗口被关闭</span>
<span class="token command"><span class="token keyword">taskkill</span> <span class="token parameter attr-name">/f</span> <span class="token parameter attr-name">/im</span> explorer.exe &gt;nul <span class="token number">2</span>&gt;nul</span><span class="token operator">&amp;</span><span class="token command"><span class="token keyword">start</span> explorer.exe</span>

<span class="token comment">REM regsvr32.exe 图标有白块</span>
<span class="token command"><span class="token keyword">regsvr32</span>.exe <span class="token parameter attr-name">/s</span> <span class="token parameter attr-name">/n</span> <span class="token parameter attr-name">/i<span class="token punctuation">:</span></span><span class="token parameter attr-name">/UserInstall</span> <span class="token variable">%SystemRoot%</span>\system32\themeui.dll</span>

<span class="token comment">:: 效果不太好，有时刷新成功，有时失败</span>
<span class="token command"><span class="token keyword">RunDll32</span> USER32,UpdatePerUserSystemParameters</span>

<span class="token comment">:: assoc文件关联有多余添加，可能报错，exe 类型几乎不会被修改成其他类型</span>
<span class="token command"><span class="token keyword">assoc</span> exe=exefile</span>
<span class="token comment">:: .=. 应该比较保险</span>
<span class="token command"><span class="token keyword">assoc</span> .=.</span>
</code></pre></div><ul><li>刷新桌面图标</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token operator">@</span><span class="token command"><span class="token keyword">echo</span> off</span>

<span class="token comment">REM inf 代码太多</span>
&gt;%tmp%\tmp.inf <span class="token punctuation">(</span>
    <span class="token command"><span class="token keyword">echo</span>;[Version]</span>
    <span class="token command"><span class="token keyword">echo</span>;Signature=$Chicago$</span>
    <span class="token command"><span class="token keyword">echo</span>;[DefaultInstall]</span>
<span class="token punctuation">)</span>
<span class="token command"><span class="token keyword">rundll32</span> SETUPAPI.DLL,InstallHinfSection DefaultInstall <span class="token number">128</span> <span class="token variable">%tmp%</span>\tmp.inf</span>
<span class="token comment">REM inf 需要%1是有效inf，win7报错：您选中INF文件不支持此安装方法</span>
<span class="token comment">REM %SystemRoot%\System32\InfDefaultInstall.exe &quot;%1&quot;</span>
</code></pre></div><h2 id="开机启动"><a href="#开机启动" class="header-anchor">#</a> 开机启动</h2> <h3 id="添加注册表"><a href="#添加注册表" class="header-anchor">#</a> 添加注册表</h3> <blockquote><p><code>Run</code>键值代表着开机启动项，也就是说在这个项下的键值会随着开机启动
（这里的开机是指用户登录，也就是说只要有登录操作就会执行，注销然后登录，也会执行这个键值）。</p></blockquote> <blockquote><p><code>RunOnce</code>键值类似于<code>Run</code>键值，唯一的区别在于，<code>RunOnce</code>键值只执行一次，操作执行后会被自动删除。</p></blockquote> <ul><li>用户启动项</li></ul> <ol><li><code>HKCU\Software\Microsoft\Windows\CurrentVersion\Run</code></li> <li><code>HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce</code></li></ol> <ul><li>本机启动项</li></ul> <ol><li><code>HKLM\SYSTEM\CurrentControlSet\Control\Session Manager</code></li> <li><code>HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run</code></li> <li><code>HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce</code></li> <li><code>HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run</code></li> <li><code>HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\RunOnce</code></li></ol> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">REG</span> ADD <span class="token string">&quot;HKCU\Software\Microsoft\Windows\CurrentVersion\Run&quot;</span> <span class="token parameter attr-name">/v</span> 软件名 <span class="token parameter attr-name">/d</span> 软件路径 <span class="token parameter attr-name">/f</span></span>
<span class="token comment">:: 或者，%号和&quot;号不能使用转移字符^转义，%号转义%%，&quot;号转义&quot;&quot;&quot;</span>
<span class="token command"><span class="token keyword">REG</span> ADD <span class="token string">&quot;HKCU\Software\Microsoft\Windows\CurrentVersion\Run&quot;</span> <span class="token parameter attr-name">/v</span> 软件名 <span class="token parameter attr-name">/d</span> <span class="token string">&quot;&quot;&quot;&quot;</span>软件路径<span class="token string">&quot;&quot;&quot; /background&quot;</span> <span class="token parameter attr-name">/f</span></span>
</code></pre></div><h3 id="启动目录"><a href="#启动目录" class="header-anchor">#</a> 启动目录</h3> <blockquote><p>把软件的快捷方式或者软件直接放在以下目录中就会开机自动运行</p></blockquote> <blockquote><p>可利用<a href="/files/%E6%B7%BB%E5%8A%A0%E5%BF%AB%E6%8D%B7%E6%96%B9%E5%BC%8F.bat">脚本添加快捷方式</a>直接在启动文件夹中生成快捷方式</p></blockquote> <blockquote><p>按<code>win+r</code>打开运行窗口，输入<code>shell:startup</code>打开启动文件夹，把快捷方式或者软件放入</p></blockquote> <ul><li>Win7及以上（当前用户）: <code>%AppData%\Microsoft\Windows\Start Menu\Programs\Startup</code></li> <li>启动目录（所有用户）: <code>%ProgramData%\Microsoft\Windows\Start Menu\Programs\StartUp</code></li></ul> <h2 id="注册表"><a href="#注册表" class="header-anchor">#</a> 注册表</h2> <blockquote><p>注册表被称为Windows操作系统的核心，它的工作原理实质是一个庞大的数据库，存放了关于计算机硬件的配置信息、
系统和应用软件的初始化信息、应用软件和文档文件的关联关系、硬件设备的说明以及各种状态信息和数据，包括Windows操作时不断引用的信息。</p></blockquote> <blockquote><p>例如：系统中的硬件资源、硬件信息、分配正在使用的端口、每个用户的配置文件、计算机上安装的应用程序以及每个应用程序可以创建的文件类型等。</p></blockquote> <blockquote><p>组策略设置的实质是修改注册表中的配置</p></blockquote> <p><strong>主要作用</strong></p> <ol><li>记录安装信息</li> <li>设置硬件</li> <li>设置软件</li> <li>定制Windows</li> <li>系统安全管理</li> <li>自动运行程序</li> <li>网络设置</li></ol> <ul><li><a href="https://zhuanlan.zhihu.com/p/72194354" target="_blank" rel="noopener noreferrer">Windows注册表内容详解<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://segmentfault.com/a/1190000016854021" target="_blank" rel="noopener noreferrer">简析Windows注册表<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.cnblogs.com/weiyinfu/p/10961872.html" target="_blank" rel="noopener noreferrer">windows注册表<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <p><strong>注册表的分支结构</strong></p> <table><thead><tr><th>注册表短根键名</th> <th>注册表长根键名</th> <th>作用</th></tr></thead> <tbody><tr><td>HKCU</td> <td>HKEY_CURRENT_USER</td> <td>存储当前用户设置的信息。当前用户登录后才执行的操作</td></tr> <tr><td>HKLM</td> <td>HKEY_LOCAL_MACHINE</td> <td>包括安装在计算机上的硬件和软件的信息。所有操作在用户登录前就执行了</td></tr> <tr><td>HKCR</td> <td>HKEY_CLASSES_ROOT</td> <td>存储Windows可识别的文件类型的详细列表，以及相关联的程序。</td></tr> <tr><td>HKEY_USERS</td> <td>HKEY_USERS</td> <td>包含使用计算机的用户的信息。</td></tr> <tr><td>HKEY_CURRENT_CONFIG</td> <td>HKEY_CURRENT_CONFIG</td> <td>这个分支包含计算机当前的硬件配置信息。</td></tr></tbody></table> <p><strong>系统默认注册表位置</strong></p> <ul><li>为所有用户安装的程序：<code>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall</code></li> <li>为当前用户安装的程序：<code>HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall</code></li> <li>64位系统中的32位程序：<code>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall</code></li></ul> <blockquote><p>这3个注册表总有一个包含你要找的程序，不包括UWP应用。</p></blockquote> <blockquote><p>隐藏指定的程序：在右边空白处（或左边的项名称）点击右键-&gt;新建-&gt;DWORD（32位）值，命名为<code>SystemComponent</code>，
并修改数据为<code>1</code>（新建后双击名称或右键点击选择修改，默认为<code>0</code>）。</p></blockquote> <blockquote><p>如果注册表项下面有&quot;SystemComponent&quot;字段并且值等于<code>1</code>时，表示这是个系统组件，而不是应用软件。</p></blockquote> <blockquote><p>如果注册表项下面有&quot;ParentKeyName&quot;字段则表示该项是某个分类下的子项，一般情况补丁才会有&quot;ParentKeyName&quot;字段。</p></blockquote> <h3 id="regini"><a href="#regini" class="header-anchor">#</a> regini</h3> <ul><li><a href="https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/regini" target="_blank" rel="noopener noreferrer">regini和其他所有命令官方文档<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <table><thead><tr><th>权限</th> <th>说明</th></tr></thead> <tbody><tr><td>1</td> <td>Administrators 完全访问</td></tr> <tr><td>2</td> <td>Administrators 只读访问</td></tr> <tr><td>3</td> <td>Administrators 读和写入访问</td></tr> <tr><td>4</td> <td>Administrators 读、写入、删除访问</td></tr> <tr><td>5</td> <td>Creator 完全访问</td></tr> <tr><td>6</td> <td>Creator 读和写入访问</td></tr> <tr><td>7</td> <td>everyone 完全访问</td></tr> <tr><td>8</td> <td>everyone 只读访问</td></tr> <tr><td>9</td> <td>everyone 读和写入访问</td></tr> <tr><td>10</td> <td>everyone 读、写入、删除访问</td></tr> <tr><td>11</td> <td>Power Users 完全访问</td></tr> <tr><td>12</td> <td>Power Users 读和写入访问</td></tr> <tr><td>13</td> <td>Power Users 读、写入、删除访问</td></tr> <tr><td>14</td> <td>System Operators 完全访问</td></tr> <tr><td>15</td> <td>System Operators 读和写入访问</td></tr> <tr><td>16</td> <td>System Operators 读、写入、删除访问</td></tr> <tr><td>17</td> <td>System 完全访问</td></tr> <tr><td>18</td> <td>System 读和写入访问</td></tr> <tr><td>19</td> <td>System 只读访问</td></tr> <tr><td>20</td> <td>Administrators 读、写、执行访问</td></tr> <tr><td>21</td> <td>Interactive User 完全访问</td></tr> <tr><td>22</td> <td>Interactive User 读和写入访问</td></tr> <tr><td>23</td> <td>Interactive User 读、写入、删除访问</td></tr></tbody></table> <h3 id="修改"><a href="#修改" class="header-anchor">#</a> 修改</h3> <ul><li><code>/v</code> 设置键名(value)</li> <li><code>/t</code> 设置数据类型(type)</li> <li><code>/d</code> 设置添加的值(data)</li> <li><code>/f</code> 表示强制(forbidden)</li></ul> <ul><li>删除桌面IE图标</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">REG</span> DELETE <span class="token string">&quot;HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{B416D21B-3B22-B6D4-BBD3-BBD452DB3D5B}&quot;</span> <span class="token parameter attr-name">/f</span></span>
</code></pre></div><ul><li>修改开机时小数字键盘不开启的问题</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">REG</span> ADD <span class="token string">&quot;HKU\.DEFAULT\Control Panel\Keyboard&quot;</span> <span class="token parameter attr-name">/v</span> InitialKeyboardIndicators <span class="token parameter attr-name">/t</span> REG_SZ <span class="token parameter attr-name">/d</span> <span class="token number">2</span> <span class="token parameter attr-name">/f</span></span>
</code></pre></div><ul><li>把图片设置为壁纸</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">REG</span> ADD <span class="token string">&quot;HKCU\Control Panel\Desktop&quot;</span> <span class="token parameter attr-name">/v</span> TileWallpaper <span class="token parameter attr-name">/d</span> <span class="token string">&quot;0&quot;</span> <span class="token parameter attr-name">/f</span> </span>
<span class="token command"><span class="token keyword">REG</span> ADD <span class="token string">&quot;HKCU\Control Panel\Desktop&quot;</span> <span class="token parameter attr-name">/v</span> Wallpaper <span class="token parameter attr-name">/d</span> <span class="token string">&quot;图片绝对路径&quot;</span> <span class="token parameter attr-name">/f</span></span>
<span class="token command"><span class="token keyword">REG</span> ADD <span class="token string">&quot;HKCU\Control Panel\Desktop&quot;</span> <span class="token parameter attr-name">/v</span> WallpaperStyle <span class="token parameter attr-name">/t</span> REG_DWORD <span class="token parameter attr-name">/d</span> <span class="token number">2</span> <span class="token parameter attr-name">/f</span></span>
<span class="token command"><span class="token keyword">RunDll32</span>.exe USER32.DLL,UpdatePerUserSystemParameters</span>
</code></pre></div><ul><li>开机自动运行</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">REG</span> ADD <span class="token string">&quot;HKCU\Software\Microsoft\Windows\CurrentVersion\Run&quot;</span> <span class="token parameter attr-name">/v</span> 自定义命名 <span class="token parameter attr-name">/d</span> <span class="token variable">%0</span> <span class="token parameter attr-name">/f</span></span>
</code></pre></div><ul><li>替换默认记事本</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">REG</span> ADD <span class="token string">&quot;HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe&quot;</span> <span class="token operator">^</span>
 <span class="token parameter attr-name">/v</span> <span class="token string">&quot;Debugger&quot;</span> <span class="token parameter attr-name">/t</span> REG_SZ <span class="token parameter attr-name">/d</span> <span class="token string">&quot;\&quot;记事本程序路径\&quot; -z&quot;</span> <span class="token parameter attr-name">/f</span></span>
</code></pre></div><ul><li>恢复系统默认记事本</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">REG</span> DELETE <span class="token string">&quot;HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe&quot;</span> <span class="token parameter attr-name">/f</span></span>
<span class="token command"><span class="token keyword">REG</span> DELETE <span class="token string">&quot;HKLM\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe&quot;</span> <span class="token parameter attr-name">/f</span></span>
<span class="token command"><span class="token keyword">REG</span> DELETE <span class="token string">&quot;HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe&quot;</span> <span class="token parameter attr-name">/v</span> <span class="token string">&quot;Debugger&quot;</span> <span class="token parameter attr-name">/f</span></span>
</code></pre></div><ul><li>Windows Defender</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 关闭“启用Windows安全中心服务”的通知</span>
<span class="token command"><span class="token keyword">REG</span> DELETE <span class="token string">&quot;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellServiceObjects\{F56F6FDD-AA9D-4618-A949-C1B91AF43B1A}&quot;</span> <span class="token parameter attr-name">/f</span></span>

<span class="token comment">:: 关闭Windows Defender</span>
<span class="token command"><span class="token keyword">REG</span> ADD <span class="token string">&quot;HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender&quot;</span> <span class="token parameter attr-name">/v</span> <span class="token string">&quot;DisableAntiSpyware&quot;</span> <span class="token parameter attr-name">/d</span> <span class="token number">1</span> <span class="token parameter attr-name">/t</span> REG_DWORD <span class="token parameter attr-name">/f</span></span>

<span class="token comment">:: 启用Windows Defender</span>
<span class="token command"><span class="token keyword">REG</span> ADD <span class="token string">&quot;HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender&quot;</span> <span class="token parameter attr-name">/v</span> <span class="token string">&quot;DisableAntiSpyware&quot;</span> <span class="token parameter attr-name">/d</span> <span class="token number">0</span> <span class="token parameter attr-name">/t</span> REG_DWORD <span class="token parameter attr-name">/f</span>   </span>
</code></pre></div><h3 id="窗口设置"><a href="#窗口设置" class="header-anchor">#</a> 窗口设置</h3> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">Mode</span> con cols=宽分辨率 lines=高分辨率</span>
</code></pre></div><blockquote><p>窗口大小是被改成了你想要的, 可是屏幕缓冲区的大小也变成了一样，这让你无法追溯屏幕打印的历史，
也就是说<code>mode</code>对于窗口大小和屏幕缓冲区大小不能单独设置。</p></blockquote> <blockquote><p>解决办法就是修改注册表，先要知道保存系统默认的<code>cmd</code>命令窗口的屏幕缓冲区大小的两个键值</p></blockquote> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 窗口大小</span>
<span class="token command"><span class="token keyword">HKEY_CURRENT_USER</span>\Console\ScreenBufferSize</span>

<span class="token comment">:: 屏幕缓冲区大小</span>
<span class="token command"><span class="token keyword">HKEY_CURRENT_USER</span>\Console\WindowSize</span>
</code></pre></div><blockquote><p>值是用的十六进制值来表示的，十六进制可以前加零来补齐为8位来理解</p> <p>十六进制的前四位是高，后四位是宽</p></blockquote> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 窗口高宽40*120</span>
<span class="token command"><span class="token keyword">REG</span> ADD <span class="token string">&quot;HKEY_CURRENT_USER\Console&quot;</span> <span class="token parameter attr-name">/t</span> REG_DWORD <span class="token parameter attr-name">/v</span> WindowSize <span class="token parameter attr-name">/d</span> 0x00280078 <span class="token parameter attr-name">/f</span></span>
<span class="token comment">:: 屏幕缓冲区高宽1000*120</span>
<span class="token command"><span class="token keyword">REG</span> ADD <span class="token string">&quot;HKEY_CURRENT_USER\Console&quot;</span> <span class="token parameter attr-name">/t</span> REG_DWORD <span class="token parameter attr-name">/v</span> ScreenBufferSize <span class="token parameter attr-name">/d</span> 0x03e80078 <span class="token parameter attr-name">/f</span></span>
</code></pre></div><h3 id="查询"><a href="#查询" class="header-anchor">#</a> 查询</h3> <div class="language-bash extra-class"><pre class="language-bash"><code>FOR /F <span class="token string">&quot;usebackq delims==&quot;</span> %i IN <span class="token punctuation">(</span><span class="token variable"><span class="token variable">`</span>REG QUERY HKCU /v onedrive /s<span class="token variable">`</span></span><span class="token punctuation">)</span> DO @echo %i
</code></pre></div><h2 id="注册服务"><a href="#注册服务" class="header-anchor">#</a> 注册服务</h2> <ul><li><a href="https://www.cnblogs.com/pingming/p/5108947.html" target="_blank" rel="noopener noreferrer">https://www.cnblogs.com/pingming/p/5108947.html<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h3 id="加入服务"><a href="#加入服务" class="header-anchor">#</a> 加入服务</h3> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: 等号后面的空格必须</span>
<span class="token command"><span class="token keyword">sc</span> create 服务名称 binPath= 执行程序路径或者命令 start= auto displayname= <span class="token string">&quot;描述&quot;</span></span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">sc</span> create frp内网穿透 binPath= D:\frp\frps.bat start= auto displayname= <span class="token string">&quot;frp内网穿透&quot;</span></span>

<span class="token command"><span class="token keyword">sc</span> create frp内网穿透 binPath= <span class="token string">&quot;cmd.exe /c D:\frp内网穿透工具\frpc.exe -c D:\frp内网穿透工具\frpc.ini&quot;</span> <span class="token operator">^</span>
 start= auto displayname= <span class="token string">&quot;frp内网穿透&quot;</span></span>
</code></pre></div><h3 id="删除服务"><a href="#删除服务" class="header-anchor">#</a> 删除服务</h3> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">sc</span> delete 服务名称</span>
</code></pre></div><h2 id="下载文件"><a href="#下载文件" class="header-anchor">#</a> 下载文件</h2> <ul><li><code>certutil</code></li></ul> <blockquote><p>用户备份证书服务管理，每次下载都会有缓存，缓存目录：<code>%USERPROFILE%\AppData\LocalLow\Microsoft\CryptnetUrlCache\Content</code></p></blockquote> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token command"><span class="token keyword">certutil</span> -urlcache -split <span class="token parameter attr-name">-f</span> https://blog-static.cnblogs.com/files/gayhub/bcn.js C:\Windows\bcn.bat</span>
</code></pre></div><ul><li><code>bitsadmin</code></li></ul> <blockquote><p><code>bitsadmin.exe</code> 是<code>windows</code>后台智能传输服务的一个工具，<code>windows</code>的自动更新，补丁之类的下载就是用这个工具来实现的。</p></blockquote> <div class="language-batch extra-class"><pre class="language-batch"><code><span class="token comment">:: /priority normal进度条等信息</span>
<span class="token command"><span class="token keyword">bitsadmin</span> <span class="token parameter attr-name">/transfer</span> 任务名 <span class="token parameter attr-name">/download</span> <span class="token parameter attr-name">/priority</span> normal https://blog-static.cnblogs.com/files/gayhub/bcn.js C:\Windows\bcn.bat</span>
</code></pre></div></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/woytu/notes-vuepress/edit/master//Shell/WindowsBatch.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2020-11-13 16:48:16</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/Shell/Shell命令.html" class="prev">
        Shell命令
      </a></span> <span class="next"><a href="/Shell/WindowsJScript.html">
        WindowsJScript
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.269009d6.js" defer></script><script src="/assets/js/3.974b9720.js" defer></script><script src="/assets/js/61.bdfbe584.js" defer></script>
  </body>
</html>
